Option Explicit On
Option Strict Off
Imports System.Runtime.InteropServices
Public Class OutlookHelper
    Dim oApp As Object
    Dim oNameSpace As Object
    Public Sub New()

    End Sub
    Private Sub CreateApplication()
        If oApp IsNot Nothing Then Exit Sub
        Dim app As Type = Type.GetTypeFromProgID("Outlook.Application")
        oApp = Activator.CreateInstance(app)
        oNameSpace = oApp.GetNamespace("MAPI")
        oNameSpace.Logon()
        
    End Sub
    Public Function CreateNewMail(ByVal [To] As String, ByVal CC As String, ByVal BCC As String, ByVal Subject As String, ByVal Body As String, ByVal Attach1 As String, ByVal Attach2 As String) As Object

        CreateApplication()
        Dim mail As Object = oApp.CreateItem(0)
        mail.To = [To]
        mail.CC = CC
        mail.BCC = BCC
        mail.Subject = Subject
        mail.Body = Body
        If (Len(Attach1)) > 0 Then mail.Attachments.Add(Attach1)
        If (Len(Attach2)) > 0 Then mail.Attachments.Add(Attach2)

        mail.Display(False)

        Return mail

    End Function

    Protected Overrides Sub Finalize()
        If (oApp IsNot Nothing) Then
            If Marshal.IsComObject(oApp) Then
                Marshal.ReleaseComObject(oApp)
            End If
            oApp = Nothing
        End If
        MyBase.Finalize()
    End Sub
End Class
